package edu.pitt.dbmi.odie.gapp.gwt.server.util.oba;

import java.util.ArrayList;
import java.util.Comparator;

public class ODIE_ObaAnnotationBean {

//	<annotationBean>
//    <score>10</score>
//    <concept>
//      <localConceptID>NCI/C0684224</localConceptID>
//      <localOntologyID>NCI</localOntologyID>
//      <isTopLevel>0</isTopLevel>
//      <preferredName>Report</preferredName>
//      <synonyms>
//        <stopword>Reported</stopword>
//      </synonyms>
//      <semanticTypes>
//        <semanticTypeBean>
//          <conceptId>NCI/C0684224</conceptId>
//          <localSemanticTypeId>T170</localSemanticTypeId>
//          <name>Intellectual Product</name>
//        </semanticTypeBean>
//        <semanticTypeBean>
//          <conceptId>NCI/C0684224</conceptId>
//          <localSemanticTypeId>T000</localSemanticTypeId>
//          <name>UMLS concept</name>
//        </semanticTypeBean>
//      </semanticTypes>
//    </concept>
//    <context class="mgrepContextBean">
//      <contextName>MGREP</contextName>
//      <isDirect>true</isDirect>
//      <term>
//        <name>Report</name>
//        <localConceptId>NCI/C0684224</localConceptId>
//        <isPreferred>1</isPreferred>
//        <dictionaryId>1</dictionaryId>
//      </term>
//      <from>2</from>
//      <to>7</to>
//    </context>
//  </annotationBean>
	
	
	private int score ;
	private String localConceptID ;
	private String cui;
	private String preferredName ;
	private boolean isTopLevel ;
	private String localOntologyID ;
	private final ArrayList<String> synonyms = new ArrayList<String>() ;
	private final ArrayList<ODIE_ObaSemanticTypeBean> localSemanticTypeIDs = new ArrayList<ODIE_ObaSemanticTypeBean>() ;
	private String termName;
	private Long sPos ;
	private Long ePos ;
	
	public static final Comparator<ODIE_ObaAnnotationBean> obaAnnotationComparator = new Comparator<ODIE_ObaAnnotationBean>() {
		@Override
		public int compare(ODIE_ObaAnnotationBean o1, ODIE_ObaAnnotationBean o2) {
			int result = (new Long(o1.getSPos() - o2.getSPos())).intValue() ;
			result = (result == 0) ? (new Long(o1.getEPos() - o2.getEPos())).intValue() : result ;
			return result;
		}
	} ;
	
	public ODIE_ObaAnnotationBean() {
		;
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer() ;
		sb.append("( " + sPos + ", " + ePos + ") ") ;
		sb.append("\tloid = " + localOntologyID) ;
		sb.append("\tlcid = " + localConceptID) ;
		sb.append("\tcn = " + preferredName + " ") ;
		sb.append("\tcui = " + cui + " ") ;
		sb.append("\ttuis = " + getLocalSemanticTypeIDsAsString() + " ") ;
		sb.append("\tsynonyms = " + getSynonymsAsString() + " ") ;
		return sb.toString();
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public String getLocalConceptID() {
		return localConceptID;
	}

	public void setLocalConceptID(String localConceptID) {
		this.localConceptID = localConceptID;
		this.cui = localConceptID.replaceAll("^.*/", "") ;
	}

	public String getPreferredName() {
		return preferredName;
	}

	public void setPreferredName(String preferredName) {
		this.preferredName = preferredName;
	}

	public boolean isTopLevel() {
		return isTopLevel;
	}

	public void setTopLevel(boolean isTopLevel) {
		this.isTopLevel = isTopLevel;
	}

	public String getLocalOntologyID() {
		return localOntologyID;
	}

	public void setLocalOntologyID(String localOntologyID) {
		this.localOntologyID = localOntologyID;
	}

	public String getTermName() {
		return termName;
	}

	public void setTermName(String termName) {
		this.termName = termName;
	}

	public Long getSPos() {
		return sPos;
	}

	public void setSPos(Long pos) {
		sPos = pos;
	}

	public Long getEPos() {
		return ePos;
	}

	public void setEPos(Long pos) {
		ePos = pos;
	}

	public ArrayList<String> getSynonyms() {
		return synonyms;
	}

	public ArrayList<ODIE_ObaSemanticTypeBean> getLocalSemanticTypeIDs() {
		return localSemanticTypeIDs ;
	}

	public String getCui() {
		return cui;
	}

	public void setCui(String cui) {
		this.cui = cui;
	}
	
	private String marshallSemanticTypeList(ArrayList<ODIE_ObaSemanticTypeBean> inputList) {
		ArrayList<String> tuis = new ArrayList<String>() ;
		for (ODIE_ObaSemanticTypeBean semanticType : inputList) {
			tuis.add(semanticType.getLocalSemanticTypeId()) ;
		}
		return marshallList(tuis) ;
	}
	
	private String marshallList(ArrayList<String> inputList) {
		String result = ODIE_ObaCoder.implodeListWithSeparator(inputList, ODIE_ObaCoder.COLON) ;
		return "[" + result + "]" ;
	}

	public String getLocalSemanticTypeIDsAsString() {
		return marshallSemanticTypeList(localSemanticTypeIDs) ;
	}
	public String getSynonymsAsString() {
		return marshallList(synonyms) ;
	}
	
	
}
